import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

public class Mytest {
    @Test
    public void test1(){
        //int[] arr={1,8,10,89,1000,1234};
        //System.out.println(binarySearch(arr, 1000));
        int[] arr=new int[100000];
        for(int i=0;i<arr.length;i++){
            arr[i]=i;
        }
        for(int i:arr){
            System.out.print(binarySearch(arr, i)+" ");
        }
    }
    int binarySearch(int[] arr,int element){
        int left=0;
        int right=arr.length-1;
        int mid=(left+right)>>1;
        while(left<=right){
            if(arr[mid]==element){
                return mid;
            }else if(arr[mid]<element){
                left=mid+1;    
            }else{
                right=mid-1;
            }
            mid=(left+right)>>1;
        }
        return -1;
    }

    @Test
    public void test2(){
        String s="MCMXCIV";
        System.out.println(romanToInt(s));
    }


    public int romanToInt(String s) {
        Map<Character,Integer> map=new HashMap<Character,Integer>();
        /*
        字符          数值
        I             1
        V             5
        X             10
        L             50
        C             100
        D             500
        M             1000
        */
        map.put('I', 1);
        map.put('V', 5);
        map.put('X', 10);
        map.put('L', 50);
        map.put('C', 100);
        map.put('D', 500);
        map.put('M', 1000);
        int sum=0;
        for(int i=0;i<s.length()-1;i++){
            if (map.get(s.charAt(i))<map.get(s.charAt(i+1))) {
                sum-=map.get(s.charAt(i));
            }else{
                sum+=map.get(s.charAt(i));
            }
        }
        sum+=map.get(s.charAt(s.length()-1));
        return sum;
    }

}
